const part = {
  async parts (parent, { articleId, date, first, skip, after }, ctx, info) {
    let startDate
    let endDate
    if (!date) {
      // 不存在表示当天
      date = new Date()
    } else {
      date = new Date(date)
    }
    date.setHours(0)
    date.setMinutes(0)
    date.setSeconds(0)
    startDate = new Date(date.getTime())
    date.setHours(23)
    date.setMinutes(59)
    date.setSeconds(59)
    endDate = new Date(date.getTime())
    // 获取某天的 article.parts
    return ctx.db.query.parts({
      first,
      skip,
      after,
      orderBy: 'createdAt_ASC',
      where: {
        createdAt_lte: endDate,
        createdAt_gte: startDate,
        article: {
          id: articleId
        }
      }
    }, info)
  }
}

module.exports = { part }
